package com.two.screen.water.balance.bean.database;

import com.google.gson.reflect.TypeToken;
import com.two.screen.water.balance.utils.CommUtils;

import org.greenrobot.greendao.converter.PropertyConverter;

import java.util.List;

public class ProductBean2OrderDBConverter implements PropertyConverter<List<ProductBean>, String> {
    @Override
    public List<ProductBean> convertToEntityProperty(String databaseValue) {
        if (databaseValue == null) {
            return null;
        }
        // 先得获得这个，然后再typeToken.getType()，否则会异常
        TypeToken<List<ProductBean>> typeToken = new TypeToken<List<ProductBean>>() {
        };
        return CommUtils.Companion.getGson().fromJson(databaseValue, typeToken.getType());
    }

    @Override
    public String convertToDatabaseValue(List<ProductBean> arrays) {
        if (arrays == null || arrays.size() == 0) {
            return null;
        } else {
            String sb = CommUtils.Companion.getGson().toJson(arrays);
            return sb;
        }
    }
}
